from django.db import models
from django.contrib.auth.models import AbstractUser
from imagekit.models import ImageSpecField,ProcessedImageField
from imagekit.processors import ResizeToFill

# Create your models here.

# 用户信息
class UserInfo(AbstractUser):
    # email = models.EmailField(max_length=254,verbose_name='email address',blank=False,null=True)
    # headImg = models.ImageField(upload_to="files/",blank=True)
    count = models.IntegerField(blank=False,null=True,verbose_name='记录登录次数',default=0)
    nickName = models.CharField(max_length=64)
    # belong = models.OneToOneField('self',on_delete=models.CASCADE,default='0')
    headImg = models.ImageField(verbose_name="图片路径",upload_to="image/",default='image/user.jpg',null=True, blank=True)

    # 方式二:
    headImg_90x90 = ProcessedImageField(
        upload_to='image/%Y/%m',
        processors=[ResizeToFill(90, 90)],
        format='JPEG',
        options={'quality': 90},
        default='image/user.jpg'
    )

    class Meta:
        db_table = 'user'  # 指明数据库表名
        verbose_name = '用户'  # 在admin站点中显示的名称
        verbose_name_plural = verbose_name  # 显示的复数名称




    def __str__(self):
        return self.id